<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';

$status = $_SESSION['status'];
$isTr = 'Trial' != $status && 'Standard' != $status;
$smarty->compile_check = true;

$smarty->display('header.tpl');

//getvalues

if($_GET[country]==''){
//$_GET[country] = 211;
}
$smarty->assign('s',$_GET);
//jobupdate
$smarty->assign('jobupdate_names',$UPDATE);
$smarty->assign('state',$state);
$smarty->assign('country',$country);
$smarty->assign('industry',$jobcategory);
$smarty->assign('function',$jobfunction);
$smarty->assign('jobstatus',$jobfillstatus);
$smarty->assign('salary',$salary);
$smarty->assign('jobtype',$jobtype);
$smarty->assign('jobCatOption',$jobCatOption);
$smarty->assign('rec_findjob',$rec_findjob);
$smarty->assign('isTr',$isTr);
$smarty->assign('usertype',$_SESSION["usertype"]);
//$smarty->assign('jobupdate_id',$_GET[jobupdate]);

$order = " ORDER BY jo_status ASC, jo_updtime DESC";
//print_r($findjob_orderby2);

$job_contact_type = "";
$and_sql = "";
switch($_SESSION["usertype"]){
	case 'employer':
		$job_contact_type = 3;
		$and_sql = " AND (FIND_IN_SET('2', jo_contact) OR FIND_IN_SET('3', jo_contact))";
		break;
	case 'recruiter':
		$job_contact_type = 2;
		$and_sql = " AND (FIND_IN_SET('2', jo_contact) OR FIND_IN_SET('3', jo_contact))";
		break;
	case 'candidate':
		$job_contact_type = 1;
		$and_sql = " AND FIND_IN_SET('1', jo_contact)";
		break;
	default:
		break;
}


if($_SESSION[usertype] == "recruiter"||$_SESSION[usertype] == "employer"){
		$addwhere = " AND (jo_username  <> '".$_SESSION[uname]."' OR (jo_username = '".$_SESSION[uname]."' AND (FIND_IN_SET('2', jo_contact)))) ";
}
$where = "  WHERE 1=1 ".$addwhere.$and_sql;

if($_GET[action]=="search"){ 
	$arr = array();
	if($_GET[keywords]!=''){ $arr[] = " (`jo_title` like '%".$_GET[keywords]."%' OR  `jo_description` like '%".$_GET[keywords]."%' OR  `jo_id` like '%".$_GET[keywords]."%' OR  `jo_copname` like '%".$_GET[keywords]."%' ) "; }
	if($_GET[city]!='') { $arr[] = " `jo_city`  like '%".$_GET[city]."%'  "; }
	if($_GET[salary]!='') { $arr[] = " `jo_salrange` like '%".$_GET[salary]."%'  ";}
	if($_GET[state]!='0'&&$_GET[state]!='') { $arr[] = " `jo_state` = '".$_GET[state]."'  ";}
	if($_GET[country]!='0'&&$_GET[country]!='') { $arr[] = " `jo_country` = '".$_GET[country]."'  "; }
	if($_GET[industry]!='0'&&$_GET[industry]!='') { $arr[] = " `jo_category` = '".$_GET[industry]."'  ";}
	if($_GET['function']!='0'&&$_GET['function']!='') { $arr[] = " `jo_function` = '".$_GET['function']."'  ";}
	if($_GET[jobstatus]!='0'&&$_GET[jobstatus]!='') { $arr[] = " `jo_status` = '".$_GET[jobstatus]."'  ";}
//	if($_GET[salary]!='0'&&$_GET[salary]!='') { $arr[] = " `jo_salrange` = '".$_GET[salary]."'  ";}
	if($_GET[jobtype]!='0'&&$_GET[jobtype]!='') { $arr[] = " `jo_type`  = '".$_GET[jobtype]."'  ";}
	if($_GET[jobcat]!='0'&&$_GET[jobcat]!='') { $arr[] = " `jo_cat`  = '".$_GET[jobcat]."'  ";}
	if($_GET[postdate]!='')  { $arr[] = " `jo_regtime`  like '%".$_GET[postdate]."%'  ";}
	if($_GET[license]!='')  { $arr[] = " `jo_license`  like '%".$_GET[license]."%'  ";}
	if($_GET[jobreq]!='')    { $arr[] = " `jo_id` like '%".$_GET[jobreq]."%'  ";}
	if($_GET[jobupdate]!='') { $arr[] = " (UNIX_TIMESTAMP( ) - `jo_updtime`) < (3600*24*".$_GET[jobupdate].")" ;}

		if($_GET[orderby]=='0'||empty($_GET[orderby])){$by = "jo_id";}
		else{
			//$rec_findjob  = array('-- SELECT ALL --','Job Title','Job Category','Job Function','Industry','City','State','Job Poster','Post Date');
			$ord   = array('','jo_title','jo_cat','jo_function','jo_category','jo_city','jo_state','jo_copname','jo_updtime');
			$by = $ord[$_GET[orderby]];
			$get[] = "orderby=$_GET[orderby]";
		}

		
		//print_r($arr);
		if(!empty($arr)){
			$implode  = @implode("AND", $arr);
			$implode  = " AND ".$implode;
			$where    .= $implode;
		}


    $order = " ORDER BY jo_status ASC, $by DESC";
}


if($_GET[tp]==1){
	
	$by    = "jo_updtime"; 
	$order = "DESC" ;

	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;$_GET[order8]==''&&$order8=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "jo_title";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "jo_category";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "jo_type";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "jo_function";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "jo_category";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "jo_city";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 7:
		   $by = "jo_copname";
		   if($_GET[order7]==1){$order_arr[7]=2; $order=" DESC ";$image_arr[7] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[7]=1;$order=" ASC ";$image_arr[7] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 8:
		   $by = "jo_updtime";
		   if($_GET[order8]==1){$order_arr[8]=2; $order=" DESC ";$image_arr[8] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[8]=1;$order=" ASC ";$image_arr[8] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
	$smarty->assign("order_arr",$order_arr);
	$smarty->assign("image_arr",$image_arr);
    $order = " ORDER BY $by $order ";

}


//echo $order;
$nav = new buildNav;
$nav->limit = 25;
$total = $DB->fetch_one_array("SELECT COUNT(*) AS count FROM pa_job $where");
$nav->total_result = $total[count];
$nav->execute("SELECT * FROM pa_job $where $order");
//echo "SELECT * FROM pa_job $where $order";
$page = $nav->pagenav();
//echo $sql2;
$i=0;
$datajob = array();
while($list2 = $DB->fetch_array($nav->sql_result)){
   $datajob[$i]              = $list2;
   $datajob[$i][jo_state]    = $state[$list2[jo_state]];
   $datajob[$i][jo_country]  = $country[$list2[jo_state]];
   $datajob[$i][jo_industry] = $jobcategory[$list2[jo_category]];
   $datajob[$i][jo_cat]		 = $jobCatOption[$list2[jo_cat]];
   $datajob[$i][jo_function] = $jobfunction[$list2[jo_function]];
   $datajob[$i][jo_salary]   = $list2[jo_salrange];
   $datajob[$i][jo_type]     = $jobtype[$list2[jo_type]];
   $datajob[$i][jo_updtime]  = date("m/d/Y",$list2[jo_updtime]);
   $i++;
}

$smarty->assign("joblist",$datajob);
$smarty->assign("page",$page);
if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("search",$reg_data);
$smarty->display('allleft.tpl');
$smarty->display('findjob.tpl');


//$smarty->display('allright.tpl');
$smarty->display('footer.tpl');
?>